/*
 * Powered By free
 * Web Site: 
 * Since 2018 - 2021
 */

package com.menhai.personmanagement.controller;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.menhai.personmanagement.entity.MbIndexInput;
import com.menhai.personmanagement.services.MbIndexInputService;
import com.menhai.personmanagement.utils.UuidUtil;

@RestController
@RequestMapping("/mbIndexInput")
public class MbIndexInputController {
	
	@Autowired
	private MbIndexInputService mbIndexInputService;
	
	@RequestMapping("/add")
    public Object addFollowupRecord(MbIndexInput mbIndexInput) throws Exception{
	   	SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	   	Map<String, Object> map = null;
	   	mbIndexInput.setIndexInputId(UuidUtil.uuid());
	   	//取到患者所属医院
	   	List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(mbIndexInput.getPersonNo());
	   	if(list!=null&&list.size()>0){
	   		String hosnum=list.get(0).get("hosnum")+"";
	   		mbIndexInput.setHosnum(hosnum);
	   	}
	   	//新增指标记录
		map = mbIndexInputService.addMbIndexInput(mbIndexInput);
		return map;
    }
	
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
 	public Object editFollowupRecord(HttpServletRequest request, HttpServletResponse response, MbIndexInput mbIndexInput) throws Exception {
 		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		Map<String, Object> map = null;
 		//取到患者所属医院
	   	List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(mbIndexInput.getPersonNo());
	   	if(list!=null&&list.size()>0){
	   		String hosnum=list.get(0).get("hosnum")+"";
	   		mbIndexInput.setHosnum(hosnum);
	   	}
	   	//编辑指标记录
		map = mbIndexInputService.editMbIndexInput(mbIndexInput);
 		return map;
 	}
 	
	@RequestMapping("/delete")
    public Object deleteFollowupRecord(MbIndexInput mbIndexInput) throws Exception{
	   	SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	   	Map<String, Object> map = null;
	   	String indexInputId=mbIndexInput.getIndexInputId();
	   	//删除指标记录
		map = mbIndexInputService.deleteById(indexInputId);
		return map;
    }
	
 	@RequestMapping(value = "/getListByCondition", method = RequestMethod.POST)
 	public Object getListByCondition(HttpServletRequest request, HttpServletResponse response, MbIndexInput mbIndexInput) throws Exception {
 		List<Map<String,Object>> list = null;
 		list = mbIndexInputService.getListByCondition(mbIndexInput);
 		return list;
 	}
 	
 	@RequestMapping(value = "/getListByConditionByPage", method = RequestMethod.POST)
 	public Object getListByConditionByPage(HttpServletRequest request, HttpServletResponse response, MbIndexInput mbIndexInput) throws Exception {
 		IPage<MbIndexInput> list = mbIndexInputService.getListByConditionByPage(mbIndexInput);
 		return list;
 	}
 	
 	@RequestMapping(value = "/getOneById", method = RequestMethod.POST)
 	public Object getOneById(HttpServletRequest request, HttpServletResponse response, MbIndexInput mbIndexInput) throws Exception {
 		List<Map<String,Object>> list = null;
 		list = mbIndexInputService.getOneById(mbIndexInput);
 		if(list.size()>0){
 			return list.get(0);
 		}
 		return list;
 	}
	
}